define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            $(".btn-add").data("area",["900px","100%"]);
            $(".btn-edit").data("area",["900px","100%"]);
            Table.api.init({
                extend: {
                    index_url: 'organization/index' + location.search,
                    add_url: 'organization/add',
                    edit_url: 'organization/edit',
/*
                    del_url: 'organization/del',
*/
                    multi_url: 'organization/multi',
                    import_url: 'organization/import',
                    table: 'organization',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'weigh',
                searchFormVisible: true,
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
/*
                        {field: 'id', title: __('Id')},
*/
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: function (value,row,index) {
                                var datetimeFormat = typeof this.datetimeFormat === 'undefined' ? 'YYYY-MM-DD' : this.datetimeFormat;
                                if (isNaN(value)) {
                                    return value ? Moment(value).format(datetimeFormat) : __('None');
                                } else {
                                    return value ? Moment(parseInt(value) * 1000).format(datetimeFormat) : __('None');
                                }
                            }
                        },
                        {field: 'organ_name', title: __('Organ_name'), operate: 'LIKE'},
/*
                        {field: 'organ_short_name', title: __('Organ_short_name'), operate: 'LIKE'},
*/
/*
                        {field: 'organ_image', title: __('Organ_image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
*/
                        {field: 'organ_type', title: __('Organ_type'), searchList: {"1":__('Organ_type 1'),"2":__('Organ_type 2'),"3":__('Organ_type 3'),"4":__('Organ_type 4'),"5":__('Organ_type 5'),"6":__('Organ_type 6')}, formatter: Table.api.formatter.normal},
                        {field: 'organ_sn', title: __('Organ_sn'), operate: 'LIKE'},
                        {field: 'organ_city', title: __('Organ_city'), operate: 'LIKE'},
                        {field: 'organ_linkman', title: __('Organ_linkman'), operate: 'LIKE'},
                        {field: 'organ_phone', title: __('Organ_phone'), operate: 'LIKE'},
                        {field: 'organ_address', title: __('Organ_address'), align:'left', operate: false},
                        {field: 'organ_tel', title: __('Organ_tel'), operate: false},
                        {field: 'organ_email', title: __('Organ_email'), operate: false},
/*
                        {field: 'pm_id', title: __('Pm_id')},
*/
                        {field: 'organ_file', title: __('Organ_file'), operate: false, formatter: Table.api.formatter.file},
/*
                        {field: 'collaborate_file', title: __('Collaborate_file'), operate: false, formatter: Table.api.formatter.file},
*/
                        {field: 'switch', title: __('Switch'), searchList: {"1":__('Yes'),"0":__('No')}, table: table, formatter: Table.api.formatter.toggle},
                        {field: 'weigh', title: __('Weigh'), operate: false},
/*
                        {field: 'updatetime', title: __('Updatetime'), addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime,operate: false},
*/
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
            table.on('post-body.bs.table',function(){
                $(".btn-editone").data("area",["900px","100%"]);
            });
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
